﻿using System;
using System.Web;
using System.Web.Security;
using com.cruxomatic.DTOs;

namespace com.cruxomatic.controllers
{
    /// <summary>
    /// Summary description for CurrentUser
    /// </summary>
    public class SessionData
    {
    
        public UserInformation CurrentUser
        {
            get {
                CheckSessionValidity();
                return (UserInformation)HttpContext.Current.Session["user"]; }
            set { HttpContext.Current.Session["user"] = value; }
        }

        public string CurrentUserRole
        {
            get
            {
                CheckSessionValidity();
                return HttpContext.Current.Session["userRole"].ToString();
            }
            set { HttpContext.Current.Session["userRole"] = value; }
        }

        public string CurrentView
        {
            get {
                return HttpContext.Current.Session["currentview"].ToString(); }
            set { HttpContext.Current.Session["currentview"] = value; }
        }

        public CompanyInformation CurrentCompany
        {
            get { return (CompanyInformation) HttpContext.Current.Session["organization"]; }
            set
            { HttpContext.Current.Session["organization"] = value; }
        }
        public string CurrentViewSection
        {
            get { 
                return HttpContext.Current.Session["currentviewsection"].ToString(); }
            set { HttpContext.Current.Session["currentviewsection"] = value; }
        }

        public object PageData
        {
            get { return HttpContext.Current.Session["pagedata"]; }
            set { HttpContext.Current.Session["pagedata"] = value; }
        }

        private void CheckSessionValidity()
        {
            if (HttpContext.Current.Session["user"] == null)
                FormsAuthentication.RedirectToLoginPage();
        }

        public bool IsFirstTimeLogin
        {
            get { return Convert.ToBoolean(HttpContext.Current.Session["IsFirstTimeLogin"]); }
            set { HttpContext.Current.Session["IsFirstTimeLogin"] = value; }
        }

        public bool IsForgotPasswordDone
        {
            get { return Convert.ToBoolean(HttpContext.Current.Session["IsForgotPasswordDone"]); }
            set { HttpContext.Current.Session["IsForgotPasswordDone"] = value; }
        }

    }
}